<template>
	<view class="goods_detail">
		<swiper  autoplay="true" indicator-dots="true" indicator-color="#eee">
			<swiper-item v-for="(item,index) in swipers" :key="index">
				<image :src="item.img_url"></image>
			</swiper-item>
		</swiper>
		<view class="box1">
			<view class="price">
				<text>现价:￥{{info.sell_price}}</text>
				<text>原价:￥{{info.market_price}}</text>
			</view>
			<view class="goods_name">
				{{info.title}}
			</view>
		</view>
		<view class="line"></view>
		<view class="box2">
			<view>货号:{{info.goods_no}}</view>
			<view>库存:{{info.stock_quantity}}件</view>
		</view>
		<view class="line"></view>
		<view class="box3">
			<view class="tit">详情介绍</view>
			<view class="content">
				<rich-text :nodes="content"></rich-text>
			</view>
		</view>
		<view class="goods-carts">
			<uni-goods-nav  :fill="true"  :options="options"  :buttonGroup="buttonGroup"  @click="onClick"  @buttonClick="buttonClick" />
		</view>
	</view>
</template>

<script>
	import uniGoodsNav from '@/uni-goods-nav/components/uni-goods-nav/uni-goods-nav.vue'
	import uniIcons from '@/uni-icons/components/uni-icons/uni-icons.vue'
	export default{
		data(){
			return{
				id:"",
				swipers:[
					{
						id:"1",
						img_url:"https://img3m1.ddimg.cn/70/2/11279342221-5_e_1.jpg"
					},
					{
						id:"2",
						img_url:"https://img3m1.ddimg.cn/70/2/11279342221-6_e_1.jpg"
					}
				],
				info:[],
				content:[],
				 options: [
					{
							// icon: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/uni-ui/goodsnav/kefu.png',
							icon:"heart-filled",
							text: '客服'
					}, 
					{
							icon: 'shop',
							text: '店铺',
					},
					{
							icon: 'cart',
							text: '购物车',
							info: 0
					},
				],
				buttonGroup: [
					{
					  text: '加入购物车',
					  backgroundColor: '#ff0000',
					  color: '#fff'
					},
					{
					  text: '立即购买',
					  backgroundColor: '#ffa200',
					  color: '#fff'
					}
				]
			}
		},
		components:{
			uniGoodsNav,
			uniIcons
		},
		onLoad(options){
			this.id = options.id;
			this.getSwipers(this.id);
			this.getDetailInfo(this.id);
			this.getDetailContent(this.id);
		},
		methods:{
			async getSwipers(id){
				const res = await this.$myRequest({
					url:"/api/getthumimages/"+id
				})
				// this.swipers = res.data.message;
				console.log(res);
			},
			async getDetailInfo(id){
				const res = await this.$myRequest({
					url:"/api/goods/getinfo/"+id
				})
				this.info = res.data.message[0];
			},
			async getDetailContent(id){
				const res = await this.$myRequest({
					url:"/api/goods/getdesc/"+id
				})
				this.content = res.data.message[0].content;
			},
			onClick (e) {
				uni.showToast({
				  title: `点击${e.content.text}`,
				  icon: 'none'
				})
				console.log(e.index);
		    },
			buttonClick (e) {
				console.log(e)
				this.options[2].info++
			}
		}
	}
</script>
<style>
	.goods_detail swiper{
		height:700rpx;
	}
	.goods_detail swiper image{
		width:100%;
		height:100%;
	}
	.box1{
		padding:20px;
		border-top:1rpx solid #ededed;
		line-height:30px;
	}
	.box1 .price{
		font-size:36rpx;
		color:#b50e03;
	}
	.box1 .price text:nth-child(2){
		font-size:28rpx;
		color:#ccc;
		margin:0 0 0 20rpx;
		text-decoration: line-through;
	}
	.line{
		border-bottom:10px solid #eee;
		padding:0 0 10px 0;
	}
	.box2,.box3{
		padding:10px 20px 0;
		font-size:32rpx;
		line-height:60rpx;
	}
	.box3 .tit{
		font-size:32rpx;
	/* 	padding-left:10px; */
		border-bottom:1px solid #eee;
		line-height:70rpx;
	}
	.box3 .content{
		/* padding:10px; */
		padding:10px 0 50px 0;
		font-size:28rpx;
		color:#333;
		line-height:50rpx;
	}
	.box3 .content img{
		width:100%;
		height:100%;
	}
	.box3 .content table{
		margin: 0 10px;
		width:100%;
	}
	.goods-carts {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		position: fixed;
		left: 0;
		right: 0;
		/* #ifdef H5 */
		left: var(--window-left);
		right: var(--window-right);
		/* #endif */
		bottom: 0;
	}
</style>